# 删除

"""
1.创建会话
"""
from sqlalchemy.orm import sessionmaker
from create_table_foreignkey import engine
Session = sessionmaker(engine)
db_session = Session()

from create_table_foreignkey import School, Student

'''
正向查询修改  删除北大学校所有的学生
'''
sch = db_session.query(School).filter(School.name == "北大").first()
db_session.query(Student).filter(Student.school_id == sch).delete()
db_session.commit()
db_session.close()